package com.njsf.excepiton;

import com.njsf.dto.ResponseJson;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@ControllerAdvice
public class GolabExceptionHandler {

    @ExceptionHandler(value = {BusinessException.class})
    @ResponseBody
    public ResponseJson handleAjaxException(BusinessException ex){
        String message = ex.getMessage();
        return new ResponseJson(102,message);
    }


    @ExceptionHandler(value = {Exception.class})
    public ModelAndView handleException(Exception ex){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("message",ex.getMessage());
        modelAndView.setViewName("500");
        return modelAndView;
    }

}
